home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINWORDS / COLLEC.ZIP / FCOLLECT.TXT next >
Text File  |  1993-06-28  |  15KB  |  456 lines

  1. '****************************************
  2. 'Collector - collects footnotes from the files in a Help project.
  3. '****************************************
  4. Declare Sub Yield Lib "Kernel"        'For yield command
  5. Sub Main
  6. Dim ErrorLev, ffPath$, ffName$, UseRTF
  7. ErrorLev = 0
  8. GetProjDir ffPath$, ffName$, ErrorLev    'What you'd think
  9. If ErrorLev <> 0 Then Goto Quit
  10. GetRunMode RunMode, ErrorLev        'Run quick, or allow access to other programs
  11. If ErrorLev <> 0 Then Goto Quit
  12. DOCorRTF UseRTF, ErrorLev        'Use .DOC files or .RTF files
  13. If ErrorLev <> 0 Then Goto Quit
  14.  
  15. JustDir ffPath$                'Separate the path from the file name...
  16. ChDir ffPath$                '...and change to that directory
  17. JustName ffName$            'Separate the file name from the path
  18. ToolsOptionsView .Hidden = 0
  19. CollectFootnotes ffName$, RunMode, UseRTF    'Main routine
  20. If  AppMinimize() Then AppRestore
  21. MsgBox "All the footnotes have been collected.", "Footnote Collector Macro", 64    'We're done!
  22. Quit:
  23. If  AppMinimize() Then AppRestore
  24. End Sub
  25.  
  26. '****************************************
  27. Sub GetProjDir(ffPath$, ffName$, ErrorLev)
  28. Dim NumFndFiles, i, n
  29.     FileFind .Location = "All local drives", .Name = "*.hpj", .Options = 0, .SortBy = 4
  30.     NumFndFiles = CountFoundFiles()
  31.     Dim HPJ$(NumFndFiles)
  32.     For i = 1 To NumFndFiles
  33.         HPJ$(i - 1) = FoundFileName$(i)
  34.     Next
  35.  
  36.     Begin Dialog UserDialog 558, 142, "Select a project file"
  37.         ListBox 14, 43, 414, 84, HPJ$(), .ListBox1
  38.         OKButton 448, 43, 88, 21
  39.         CancelButton 448, 67, 88, 21
  40.         Text 14, 9, 475, 13, "Select the Windows Help project from which to collect"
  41.         Text 14, 22, 187, 13, "the footnote information."
  42.     End Dialog
  43.     Dim HPJ As UserDialog
  44.     n = Dialog(HPJ)        'Figure out how to do On Error here
  45.     If n = 0 Then ErrorLev = 1
  46.     ffName$ = HPJ$(HPJ.ListBox1)
  47.     ffPath$ = ffName$
  48. End Sub
  49.  
  50. '****************************************
  51. Sub GetRunMode(Fast, ErrorLev)
  52. Dim n
  53.     Begin Dialog UserDialog 484, 156, "Select Run Mode"
  54.         OKButton 379, 6, 88, 21
  55.         CancelButton 379, 30, 88, 21
  56.         OptionGroup  .Opt1
  57.             OptionButton 10, 6, 320, 16, "FAST MODE - Runs quick as possible,"
  58.             OptionButton 10, 55, 344, 16, "RELAXED MODE - Slower, but allows you"
  59.         Text 33, 21, 256, 13, "but tends to be a hog with system"
  60.         Text 33, 34, 80, 13, "resources."
  61.         Text 33, 70, 311, 13, "access to other programs, such as email,"
  62.         Text 33, 83, 215, 13, "games to pass the time, etc."
  63.         Text 33, 108, 380, 13, "Both modes will reduce the application to an icon."
  64.         Text 33, 121, 343, 13, "Without having to update the screen, macros"
  65.         Text 33, 134, 191, 13, "typically run much faster."
  66.     End Dialog
  67.     Dim dlg As UserDialog
  68.     n = Dialog(dlg)
  69.     If n = 0 Then ErrorLev = 1    'If they click Cancel, let the main routine know
  70.     If dlg.Opt1 = 0 Then
  71.         Fast = 1    'run without pauses
  72.     Else
  73.         Fast = 0    'run in minimized mode
  74.     EndIf
  75. End Sub
  76.  
  77. '****************************************
  78. Sub DOCorRTF(UseRTF, ErrorLev)
  79. Dim n
  80.     Begin Dialog UserDialog 460, 96, "Use which file type?"
  81.         Text 10, 6, 325, 13, "If available, this macro will run much faster"
  82.         Text 10, 19, 312, 13, "on .DOC files than on .RTF files.  Do you"
  83.         Text 10, 33, 209, 13, "want to use the .DOC files?"
  84.         OptionGroup  .Opt1
  85.             OptionButton 42, 50, 137, 16, "Use .RTF files"
  86.             OptionButton 42, 66, 140, 16, "Use .DOC files"
  87.         OKButton 362, 11, 88, 21
  88.         CancelButton 362, 35, 88, 21
  89.     End Dialog
  90.     Dim dlg As UserDialog
  91.     n = Dialog(dlg)
  92.     If n = 0 Then ErrorLev = 1    'If they click Cancel, let the main routine know
  93.     If dlg.Opt1 = 0 Then UseRTF = 1    'They chose to use .RTF files (default)
  94. End Sub
  95.  
  96.  
  97. '****************************************
  98. Sub JustDir(t$)        'Separate the path from the file name
  99. Dim i
  100.     i = Len(t$)
  101.     While Mid$(t$, i, 1) <> "\"
  102.         i = i - 1
  103.     Wend
  104.     i = i - 1
  105.     t$ = Left$(t$, i)
  106. End Sub
  107.  
  108. '****************************************
  109. Sub JustName(t$)        'Separate the file name from the path
  110. Dim i
  111.     i = Len(t$)
  112.     While Mid$(t$, i, 1) <> "\"
  113.         i = i - 1
  114.     Wend
  115.     i = Len(t$) - i
  116.     t$ = Right$(t$, i)
  117. End Sub
  118.  
  119. '****************************************
  120. Sub FindFilesSection(ffName$)
  121. 'Locates the [Files] section of a .HPJ file
  122. Dim done, r$
  123. Open ffName$ For Input As #1    'Open the .HPJ file
  124. done = 0
  125. On Error Goto Oops
  126. While done = 0
  127.     Read #1, r$        'Get a line from the file
  128.     r$ = Left$(r$, 7)
  129.     If(r$ = "[FILES]" Or r$ = "[files]" Or r$ = "[Files]") Then
  130.         done = 1
  131.     EndIf
  132. Oops:
  133. Wend
  134. End Sub
  135.  
  136. '****************************************
  137. Sub CleanupName(rtf$)    'Gets rid of any comments after the filename
  138. Dim n1, n2
  139.     n1 = InStr(rtf$, ".RTF")
  140.     n2 = InStr(rtf$, ".rtf")
  141.     If n1 <> 0 Then rtf$ = Left$(rtf$, n1 + 3)
  142.     If n2 <> 0 Then rtf$ = Left$(rtf$, n2 + 3)
  143. End Sub
  144.  
  145. '****************************************
  146. Sub CollectFootnotes(ffName$, RunMode, UseRTF)
  147. 'This is just Collector as a subroutine, with the RunMode option added.
  148. 'We've already changed directories, and have the filename, so first we need to
  149. 'find out how many files there are.  Then dim an array and fill it up.  Then
  150. 'Collector can handle the rest, as is.
  151.  
  152. Dim HelpTitle$, KeyTitle$, Browse$, KeyWord$, HelpID$, Comments$
  153. Dim BuildTag$, EntryMacro$, r$, RTFCount, ffAppend, done, n1, n2, i
  154.  
  155. 'Find out if we should append to TRACKER.CSV or create a new one
  156. r$ = Files$("tracker.csv")
  157. If r$ <> "" Then AppendCSV ffAppend
  158.  
  159. 'This section counts the files
  160. FindFilesSection ffName$        'Open the .HPJ file and locate the [Files] section
  161. done = 0
  162. RTFCount = 0
  163. While done = 0
  164.     Input #1, r$
  165.     If Eof(1) Then done = 1
  166.     If Left$(r$, 1) <> ";" Then
  167.         n1 = InStr(r$, ".RTF")
  168.         n2 = InStr(r$, ".rtf")
  169.         If(n1 > 0 Or n2 > 0) Then
  170.             RTFCount = RTFCount + 1
  171.         Else
  172.             done = 1
  173.         EndIf
  174.     EndIf
  175. Wend
  176. Close #1        'Close the .HPJ file so we can open it again
  177.  
  178. 'Now we open the .HPJ file and read the file names into an array
  179. FindFilesSection    ffName$    'Reopen the file and find the [FILES] section again
  180. Dim RTF$(RTFCount)
  181. For i = 1 To RTFCount
  182.     Input #1, r$
  183.     If Left$(r$, 1) <> ";" Then
  184.         CleanupName r$
  185.         RTF$(i) = r$
  186.     Else
  187.         i = i - 1
  188.     EndIf
  189. Next                'Now we have the array of names and can read them.
  190. Close #1
  191.  
  192. If UseRTF = 0 Then        'If user wants to read .DOC files
  193.     For i = 1 To RTFCount
  194.         RTF$(i) = Left$(RTF$(i), Len(RTF$(i)) - 3)
  195.         RTF$(i) = RTF$(i) + "doc"
  196.     Next
  197. EndIf
  198.  
  199. 'Open a text file for writing, and overwrite if already existing, then write the column titles to it.
  200.  
  201. If ffAppend = 1 Then
  202.     Open "TRACKER.CSV" For Append As #1
  203. Else
  204.     Open "TRACKER.CSV" For Output As #1
  205. EndIf
  206.  
  207. If ffAppend = 0 Then
  208.     Write #1, "File Name", \
  209.         "Topic Title", \
  210.         "Keyword Search Title", \
  211.         "Context ID (Help Token)", \
  212.         "Browse Seq.", \
  213.         "Key Words", \
  214.         "Comments", \
  215.         "Build Tags", \
  216.         "Entry Macro"
  217. EndIf
  218.  
  219. REM    WOPR.Echo 0        'Turn off screen updates
  220.  
  221. AppMinimize            'Turn off screen updates by minimizing
  222. 'Start opening TOC files and run the main routines.
  223. For i = 1 To RTFCount
  224.     DisableAutoMacros 1        'Don't let Auto... macros mess us up
  225.     FileOpen .Name = RTF$(i), .ReadOnly = 0
  226.     If Not DocMaximize() Then DocMaximize
  227.  
  228.     'Process the help topics and get the footnotes
  229.     GetFootNotes RTF$(i), KeyTitle$, HelpID$, Browse$, KeyWord$, Comments$, \
  230.     BuildTag$, EntryMacro$
  231.  
  232.  
  233.     SetDirty 0        'Mark file as unchanged
  234.     FileClose             'Close file without saving it.
  235. Next                'Next file
  236.  
  237. 'Whatever the outcome, close up shop and put things back the way they were.
  238. TheEnd:                'On Error, close the file and end the macro.
  239. Close #1                'Close TRACKER.CSV
  240. DisableAutoMacros 0        'Reenable AutoMacros
  241. REM    WOPR.Echo 1        'Echo back on
  242. End Sub    
  243.  
  244. '*************************************************
  245. 'Processes all help topics in the document
  246. Sub GetFootNotes(FileNm$, KeyTitle$, HelpID$, Browse$, KeyWord$, Comments$, \
  247.     BuildTag$, EntryMacro$)
  248.  
  249. Print "Working on " + FileNm$    'Let user know what's up....
  250.  
  251. 'Do the very first topic in the file, which is assumed to be the first thing in the file.
  252. StartOfDocument
  253. 'Initialize variables for each heading
  254.     HelpTitle$ = "-"
  255.     KeyTitle$ = "-"
  256.     Browse$   = "-"
  257.     KeyWord$  = "-"
  258.     HelpID$   = "-"
  259.     Comments$  = "-"
  260.     BuildTag$ = "-"
  261.     EntryMacro$ = "-"
  262. GetFeet FileNm$, KeyTitle$, HelpID$, Browse$, KeyWo